﻿using System;
using System.Configuration;
using System.Data.Services.Client;
using System.Web.Security;

namespace WebPages
{
    public partial class _Default : System.Web.UI.Page
    {
        bool UserExists(string userName)
        {
            try
            {
                if (Membership.GetUser(userName) == null) return false;
            }
            catch (DataServiceQueryException)
            {
                return false;
            }

            return true;
        }

        void AppNotInitiated()
        {
            Response.Redirect("Admin/InitApp.aspx", true);
        }

        void UpdateSessionStateMessage()
        {
            if (String.IsNullOrEmpty(Session["Started"] as string))
                Session["Started"] = String.Format(@"Your current session has id ""{0}"" and was started {1}.", Session.SessionID , DateTime.Now);

            SessionStateMessage.Text = Session["Started"] as string;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserExists(ConfigurationManager.AppSettings["AdminName"]))
                AppNotInitiated();

            UpdateSessionStateMessage();
        }
    }
}
